<?php

App::uses('AppModel', 'Model');

/**
 * Event Model
 *
 * @property Place $Place
 * @property Chapter $Chapter
 * @property User $User
 */
class Event extends AppModel {

    /**
     * Display field
     *
     * @var string
     */
    public $displayField = 'name';

    //The Associations below have been created with all possible keys, those that are not needed can be removed

    /**
     * belongsTo associations
     *
     * @var array
     */
    public $belongsTo = array(
        'Place' => array(
            'className' => 'Place',
            'foreignKey' => 'place_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Chapter' => array(
            'className' => 'Chapter',
            'foreignKey' => 'chapter_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    public $hasMany = array(
        'Registration' => array(
            'className' => 'Registration',
            'foreignKey' => 'event_id',
            'conditions' => '',
            'fields' => '',
            'order' => 'created DESC'
        )
    );
    public $validate = array(
        'name' => array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank'
        ),
        'desc' => array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank'
        )
    );
    public $virtualFields = array(
        'registered' => '(SELECT count(*) FROM registrations WHERE event_id = Event.id )'
    );
}
